package xyz.bali16.module.follow.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import xyz.bali16.application.controller.BaseController;
import xyz.bali16.application.core.enums.ApiEnum;
import xyz.bali16.application.core.model.Result;
import xyz.bali16.module.follow.service.FollowService;

import java.util.List;
import java.util.Map;

import static xyz.bali16.application.core.model.Result.*;

/**
 * @author bali2 on 9/3/2023.
 * @version 1.0
 */
@RestController
@RequestMapping(BaseController.API + "follow")
@Api(tags = "关注接口")
@AllArgsConstructor

public class FollowController extends BaseController {
    @Autowired
    FollowService followService;

    @GetMapping("getFolloweesList")
    //@PreAuthorize("@auth.permission('plugin:follow:query')")
    @ApiOperation(value = "查询关注的人列表")
    public Result<List<Map<String, Object>>> getFolloweesList(String userId, Integer currPage, Integer pageSize) {
        return success(ApiEnum.GET_SUCCESS, followService.findFollowees(userId, currPage, pageSize));
    }

    @GetMapping("getFollowerList")
    //@PreAuthorize("@auth.permission('plugin:follow:query')")
    @ApiOperation(value = "查询粉丝列表")
    public Result<List<Map<String, Object>>> getFollowerList(String userId, Integer currPage, Integer pageSize) {
        return success(ApiEnum.GET_SUCCESS, followService.findFollowers(userId, currPage, pageSize));
    }

    @GetMapping("getFollowerCount")
    //@PreAuthorize("@auth.permission('plugin:follow:query')")
    @ApiOperation("获取粉丝数量")
    public Result<Long> getFollowerCount(String userId) {
        return success(followService.findFollowerCount(userId));
    }

    @GetMapping("getFolloweeCount")
    //@PreAuthorize("@auth.permission('plugin:follow:query')")
    @ApiOperation("获取关注数量")
    public Result<Long> getFolloweeCount(String userId) {
        return success(followService.findFolloweeCount(userId));
    }

    @GetMapping("isFollow")
    @ApiOperation("是否关注")
    //@PreAuthorize("@auth.permission('plugin:follow:query')")
    public Result<Boolean> hasFollowed(String userId, String followeeUserId) {
        return success(followService.hasFollowed(userId, followeeUserId));
    }

    @GetMapping("follow")
    @ApiOperation("关注")
    //@PreAuthorize("@auth.permission('plugin:follow:add')")
    public Result<String> follow(String userId, String targetUserId) {
        followService.follow(userId, targetUserId);
        return success("关注成功");
    }

    @GetMapping("unfollow")
    @ApiOperation("取消关注")
    //@PreAuthorize("@auth.permission('plugin:follow:delete')")
    public Result<String> unfollow(String userId, String targetUserId) {
        followService.unfollow(userId, targetUserId);
        return success("取消关注成功");
    }

}
